def permute(s1, s2):
    s = list(s1)
    if len(s2) != len(s1):
        return False

    def backtrack(start=0):
        # 当前排列的末尾
        if start == len(s):
            result.append(''.join(s))
            return

        for i in range(start, len(s)):
            # 交换操作
            s[start], s[i] = s[i], s[start]
            # 继续递归填充下一个位置
            backtrack(start + 1)
            # 撤销交换（回溯）
            s[start], s[i] = s[i], s[start]

    result = []
    backtrack()
    for i in result:
        if i == s2:
            return True
    return False


# 示例
print(permute("abc", "cba"))
